package com.atguigu.state;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 抽奖活动类
 * @create: 2022-03-30 11:20
 **/
public class RaffleActivity {
    /**
     * 表示抽奖活动的当前状态，是变化的（跟随过程而变化）
     */
    State state = null;
    /**
     * 奖品数量
     */
    int count = 0;
    /**
     * 四个属性表示四种状态（1.不可以抽奖；2.可以抽奖；3.发放奖品；4.奖品发放完了）
     */
    State noRaffleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleState(this);
    State dispenseState = new DispenseState(this);
    State dispenseOutState = new DispenseOutState(this);
    /**
     * 构造器
     * 初始化当前的状态为 noRaffleState（不能抽奖的状态）
     * @param count 初始化奖品的数量
     */
    public RaffleActivity(int count) {
        this.state = getNoRaffleState();
        this.count = count;
    }

    /**
     * 扣除积分，调用当前状态的 deductMoney 方法
     */
    public void deductMoney(){
        state.deductMoney();
    }

    /**
     * 抽奖
     */
    public void raffle(){
        //如果当前的状态是抽奖成功
        if(state.raffle()){
            //领取奖品
            state.dispensePrize();
        }
    }


    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    /**
     * 这里注意，每领取一次奖品，count--
     * @return 当前抽奖前，物品的剩余量
     */
    public int getCount() {
        int curCount = count;
        count--;
        return curCount;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public State getNoRaffleState() {
        return noRaffleState;
    }

    public void setNoRaffleState(State noRaffleState) {
        this.noRaffleState = noRaffleState;
    }

    public State getCanRaffleState() {
        return canRaffleState;
    }

    public void setCanRaffleState(State canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public State getDispenseOutState() {
        return dispenseOutState;
    }

    public void setDispenseOutState(State dispenseOutState) {
        this.dispenseOutState = dispenseOutState;
    }
}
